package com.tj.tj_java.mapper;

import com.tj.tj_java.pojo.Favorite;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.tj.tj_java.pojo.Music;

import java.util.List;

@Mapper
public interface FavoriteMapper {

    //获取该用户的收藏夹歌单
    @Select("select * from favorite,musics where Favorite.userId=#{userId} and musics.musicId=Favorite.musicId")
    List<Music> getUserMusicById(int userId);

    //收藏夹模糊查询
    @Select("select * from favorite,musics where Favorite.userId=#{userId} and musics.musicId=Favorite.musicId and musics.musicTitle like CONCAT('%', #{musicTitle},'%')")
    List<Music> getUserFavoriteMusicList(int userId,String musicTitle);




    //收藏
    @Insert("INSERT INTO favorite (userId,musicId) VALUES (#{userId},#{musicId})")
    void addFavorite(int userId, int musicId);

    //取消收藏
    @Delete("delete from favorite where userId=#{userId} and musicId=#{musicId}")
    void removeFavorite(int userId, int musicId);


    //***********************
    //通过 用户id 获取 该用户的收藏夹
    @Select("select * from favorite where userId=#{userId}")
    List<Favorite> getFavoriteById(int userId);
}
